from django.contrib.auth.models import Group
from rest_framework.permissions import IsAdminUser,DjangoModelPermissions,DjangoModelPermissions
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from users.models import User

from ..serializers.groups import GroupSerialzier
from ..serializers.admin import AdminSerialzier
from ..utils import PageNum


class AdminView(ModelViewSet):
    # 指定查询集
    queryset = User.objects.filter(is_staff=True)
    # 指定序列化器
    serializer_class = AdminSerialzier
    # 指定权限
    permission_classes = [IsAdminUser,DjangoModelPermissions]
    # 指定分页器
    pagination_class = PageNum


    # 获取所有组
    def simple(self, request):
        # 1、查询权限类型表，获取权限类型
        data = Group.objects.all()
        # 2、序列化返回
        ser = GroupSerialzier(data, many=True)
        return Response(ser.data)

